package com.ti.demo.etl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentTransformer;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 修改 Document 的 Id，我们希望 ETL 任务能可重复执行，因此 Id 不能随机生成
 * @Author Triagen
 * @Date 2025/10/23 10:37
 */
public class IdTransformer implements DocumentTransformer {

    private static final String ID = "id";

    @Override
    public List<Document> apply(List<Document> documents) {
        List<Document> copiedDocument = new ArrayList<>();
         documents.forEach(document -> {
             Document.Builder builder = document.mutate().id(ID);
             builder.id(String.valueOf(builder.build().hashCode()));
             copiedDocument.add(builder.build());
         });
        return copiedDocument;
    }
}
